// 页面路径：store/index.js
import {
    createStore
} from 'vuex'
const store = createStore({
    state: {
        jssdk_status: 0,
        base: {
            yg_set: {},
            show_base: {},
            zdm_a: {},
        },
        menus: [],
        midIndex: -1,
        city: "",
        district: "",
        xiaoqu: {},
        userinfo: null,
        location: null,
    },
    mutations: {

        set_location(state, locaiton) {
            // 变更状态
            state.location = locaiton
        },

        set_xiaoqu(state, xiaoqu) {
            // 变更状态
            uni.storage.set("xiaoqu", xiaoqu);
            state.xiaoqu = xiaoqu
        },

        set_user(state, user) {
            // 变更状态
            uni.storage.set("userinfo", user);
            if (user) {
                state.userinfo = user;
            } else {
                state.userinfo = null;
            }

        },


        set_city(state, city) {
            // 变更状态
            state.city = city;
        },
        set_district(state, district) {
            // 变更状态
            state.district = district;
        },
        set_jssdk_status(state, status) {
            // 变更状态
            state.jssdk_status = status;
        },
        set_base(state, base) {
            // 变更状态
            uni.storage.set("base", base);
            state.base = base;
        },
        set_menus(state, menus) {
            // 变更状态
            if (menus.length % 2 == 1) {
                state.midIndex = Math.floor(menus.length / 2);
            }
            state.menus = menus;
        },

    },
    actions: {
    },
    getters: {
        getUserinfo: (state) => () => {
            return state.userinfo || {};
        },
    }
})

export default store